package com.framewiki.gpt.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * @ProjectName: framewiki-gpt
 * @Package: com.framewiki.gpt.config
 * @ClassName: GptConfig
 * @Description: GPT配置
 * @Author: xiaLin
 * @Date: 2023/6/10 18:16
 * @Version: 1.0
 */
@Component
@Configuration
public class ChatConfig {

  /**
   * 环境
   */
  @Value("${spring.profiles.active}")
  private String active;

  /**
   * 默认环境
   */
  private final String defaultActive = "prod";

  /**
   * 地址
   */
  private final String OPEN_AI_URI = "https://api.openai.com/v1/";

  /**
   * 测试地址
   */
  private final String TEST_OPEN_AI_URI = "https://vpn.itizzy.com/v1/";

  /**
   * 请求机构
   * 列出模型
   * 检索模型
   */
  private final String MODEL_LIST = "models";

  /**
   * 聊天完成
   */
  private final String CREATE_CHAT_COMPLETION = "chat/completions";

  /**
   * 创建对话
   */
  private final String CREATE_COMPLETION = "completions";

  /**
   * ;
   * 聊天完成地址
   *
   * @return
   */
  public String getCreateChatCompletion() {
    StringBuffer address = new StringBuffer(getAddress());
    address.append(CREATE_CHAT_COMPLETION);
    // 返回结果
    return address.toString();
  }

  /**
   * 获取地址
   */
  private String getAddress() {
    if (active.startsWith(defaultActive)) {
      return OPEN_AI_URI;
    } else {
      return TEST_OPEN_AI_URI;
    }
  }
}
